package com.bodu.system.controller;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.PageResult;
import com.bodu.core.entity.result.Result;
import com.bodu.global.annon.TraceLog;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.system.entity.request.CodeGenConfigRequest;
import com.bodu.system.entity.vo.CodeGenConfigVo;
import com.bodu.system.service.CodeGenConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @author Administrator
*/
@Api(tags = "代码生成工具")
@RestController
@RequestMapping("/codeGenConfig")
public class CodeGenConfigController extends AbstractCommonController<CodeGenConfigService, CodeGenConfigRequest, CodeGenConfigVo>{

    private final CodeGenConfigService codeGenConfigService;

    public CodeGenConfigController(CodeGenConfigService codeGenConfigService) {
        this.codeGenConfigService = codeGenConfigService;
    }

    @ApiOperation("详情")
    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(codeGenConfigService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("生成代码")
    public Result<Integer> save(@RequestBody CodeGenConfigRequest codeGenConfigRequest) {
        return super.save(codeGenConfigService, codeGenConfigRequest);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新代码")
    public Result<Integer> update(@RequestBody CodeGenConfigRequest codeGenConfigRequest) {
        return super.update(codeGenConfigService, codeGenConfigRequest);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("数据表")
    public Result<List<CodeGenConfigVo>> listPage(@RequestBody ParamReq<CodeGenConfigRequest> req)  {
        return super.listPage(codeGenConfigService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("数据表-统计")
    public Result<Integer> countPage(@RequestBody ParamReq<CodeGenConfigRequest> req)  {
        return super.countPage(codeGenConfigService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("数据表-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<CodeGenConfigRequest> req)  {
        return super.page(codeGenConfigService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除生成代码")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(codeGenConfigService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除生成代码")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(@PathVariable("ids") List<Long> ids) {
        return super.batchDelete(codeGenConfigService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }
}
